const express = require("express");
const router = express.Router();
const orderItemController = require("../controllers/orderItemController");

/**
 * @route GET /api/order-items
 * @description 获取订单项列表（支持分页、筛选：订单ID、产品ID）
 * @access Public
 */
router.get("/", orderItemController.getAllOrderItems);

/**
 * @route GET /api/order-items/:id
 * @description 获取单个订单项详情（联表：订单+产品+用户信息）
 * @access Public
 */
router.get("/:id", orderItemController.getOrderItemById);

/**
 * @route POST /api/order-items
 * @description 创建新订单项（需关联订单和产品）
 * @access Public
 */
router.post("/", orderItemController.createOrderItem);

/**
 * @route PUT /api/order-items/:id
 * @description 更新订单项（仅允许修改数量、价格等非关联字段）
 * @access Public
 */
router.put("/:id", orderItemController.updateOrderItem);

/**
 * @route DELETE /api/order-items/:id
 * @description 删除订单项
 * @access Public
 */
router.delete("/:id", orderItemController.deleteOrderItem);

module.exports = router;
